package com.wgt.strategy.objSort;

/**
 * 猫 类型
 * Created by wgt on 2017/7/20.
 */
public class Cat implements Comparable{

    private String name;    //姓名
    private Integer height; //身高
    private Integer age;    //年龄

    /**
     * 初始化方法
     * @param name
     * @param height
     * @param age
     */
    public Cat(String name, Integer height, Integer age) {
        this.name = name;
        if (height==null||height.intValue()<0){
            throw new IllegalArgumentException("height can't less than 0");
        }
        this.height = height;
        if (age==null||age.intValue()<0){
            throw new IllegalArgumentException("age can't less than 0");
        }
        this.age = age;
    }

    /**
     * 可以根据身高或者年龄进行判断两者的大小
     * @param o 与其对比的对象
     * @return
     */
    @Override
    public int compareTo(Object o) {
        if (o instanceof Cat){
            Cat cat = (Cat)o;
            if (this.height.intValue()<cat.height.intValue())return -1;
            else if (this.height.intValue()>cat.height) return 1;
            else return 0;
        }

        throw new ClassCastException("Object class type conversion error");
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getHeight() {
        return height;
    }

    public void setHeight(Integer height) {
        this.height = height;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Cat{" +
                "name='" + name + '\'' +
                ", height=" + height +
                ", age=" + age +
                '}';
    }


}
